<!--  -->
<template>
    <el-button placeholder="OBS创建" @click="onClickOBS">OBS创建</el-button>

    <el-dialog v-model="obsDayShow" title="OBS创建" width="30%">
        <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="请输入开始日期">
                <el-date-picker v-model="obsStart" type="date" placeholder="选择一天" size="small" format="YYYY-MM-DD" value-format="YYYY-MM-DD" />
            </el-form-item>

            <el-form-item v-if="projectShow">
                <el-switch style="--el-switch-on-color: #13ce66; --el-switch-off-color: #13ce66" v-model="obsProject" size="large" active-text="道路开通" active-value="road-open" inactive-text="路网提取" inactive-value="road-network" />
            </el-form-item>
        </el-form>

        <template #footer>
            <span class="dialog-footer">
                <el-button @click="obsDayCancel">取消</el-button>
                <el-button type="primary" @click="obsDaySend">
                    确认
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script setup lang="ts">
import {ref}       from "vue"
import {ElMessage} from 'element-plus'
import request     from "@/utils/system/request";

const props = defineProps({
    url        : {
        type   : String,
        default: () => {
            return ""
        }
    },
    projectShow: {
        type   : Boolean,
        default: () => {
            return false
        }
    },
})


function onClickOBS() {
    obsDayShow.value = true
}

function sendDownload(data: object) {
    return request({
        url   : props.url,
        method: 'post',
        data
    })
}

const obsDayShow = ref(false)
const obsStart   = ref(null)
const obsProject = ref(null)

/**
 * 取消发送
 */
function obsDayCancel() {
    obsDayShow.value = false
}

/**
 * 发送全天邮件
 */
function obsDaySend() {
    obsDayShow.value = false

    if (!obsStart.value) {
        ElMessage.error('请填写日期')
        return
    }

    if (props.projectShow && !obsProject.value) {
        ElMessage.error('请选择类型')
        return
    }

    let data: any = {}

    data.date = obsStart.value
    if (props.projectShow) {
        data.project = obsProject.value
    }

    sendDownload(data).then((res: any) => {
        if (res.code === 200) {
            ElMessage.success("成功")
        }
        else {
            ElMessage.error("失败")
        }
    })
}
</script>

<style lang="scss" scoped>

</style>
